<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="编号、领券者、商家名称、商家账号" clearable style="width: 260px"></el-input>
      </el-form-item>
      <el-form-item label="起始时间">
		<el-date-picker
          v-model="dataForm.startTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="起始时间">
		</el-date-picker>
	  </el-form-item>
	  <el-form-item label="结束时间">
		<el-date-picker
          v-model="dataForm.endTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="结束时间">
		</el-date-picker>
	  </el-form-item>
      <el-form-item label="记录类型">
		<el-select v-model="dataForm.logsType" placeholder="记录类型">
          <el-option label="全部" value=""></el-option>
		  <el-option label="待确认" value="0" ></el-option>
		  <el-option label="商家已确认" value="1" ></el-option>
		  <el-option label="交易完成" value="2" ></el-option>
          <el-option label="预约拒绝" value="3" ></el-option>
		  <el-option label="预约失败" value="4" ></el-option>
		  <el-option label="未预约" value="5" ></el-option>
          <el-option label="已过期" value="6" ></el-option>
		</el-select>
	  </el-form-item>
      <el-form-item label="券类型">
		<el-select v-model="dataForm.goodsType" placeholder="券类型">
		  <el-option label="全部" value="" ></el-option>
		  <el-option label="抵扣券" value="1" ></el-option>
          <el-option label="体验券" value="2" ></el-option>
		</el-select>
	  </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <!-- <el-button v-if="isAuth('goods:shoppinggoods:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('goods:shoppinggoods:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <!-- <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column> -->
      <el-table-column
        prop="orderNo"
        header-align="center"
        align="center"
        label="编号"
        width="200px">
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="创建时间"
        width="155px">
      </el-table-column>
      <el-table-column
        prop="goodsImg"
        header-align="center"
        align="center"
        label="图片"
        width="160px">
        <template slot-scope="scope">
          <el-popover
            placement="right"
            title=""
            trigger="hover">
            <img :src="'http://image.yilianbaihui.cn/consumer/goods/' + scope.row.goodsImg"/>
            <img slot="reference" :src="'http://image.yilianbaihui.cn/consumer/goods/' + scope.row.goodsImg" :alt="'http://image.yilianbaihui.cn/consumer/goods/' + scope.row.goodsImg" style="max-height: 30px;max-width: 80px">
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column
        prop="goodsName"
        header-align="center"
        align="center"
        label="券名称"
        width="200px">
      </el-table-column>
      <el-table-column
        prop="goodsCount"
        header-align="center"
        align="center"
        label="券数量">
      </el-table-column>
      <el-table-column
        prop="payTrueName"
        header-align="center"
        align="center"
        label="领券者">
      </el-table-column>
      <el-table-column
        prop="payName"
        header-align="center"
        align="center"
        label="账号">
      </el-table-column>
      <el-table-column
        prop="typeId"
        header-align="center"
        align="center"
        label="券类型"
        width="160px">
        <template slot-scope="scope">
          <span v-if="scope.row.typeId == 0">普通商品</span>
          <span v-else-if="scope.row.typeId == 1">抵扣券</span>
          <span v-else-if="scope.row.typeId == 2">体验券</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="orderStatus"
        header-align="center"
        align="center"
        label="状态">
      </el-table-column>
      <el-table-column
        prop="shopTrueName"
        header-align="center"
        align="center"
        label="商家名称"
        width="180px">
      </el-table-column>
      <el-table-column
        prop="shopName"
        header-align="center"
        align="center"
        label="商家账号"
        width="150px">
      </el-table-column>
      <el-table-column
        prop="shopUserType"
        header-align="center"
        align="center"
        label="商家类型">
      </el-table-column>
      <el-table-column
        prop="appointmentTime"
        header-align="center"
        align="center"
        label="预约时间"
        width="155px">
      </el-table-column>
      <el-table-column
        prop="confirmTime"
        header-align="center"
        align="center"
        label="确认时间"
        width="155px">
      </el-table-column>
      <el-table-column
        prop="successTime"
        header-align="center"
        align="center"
        label="完成时间"
        width="155px">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        dataForm: {
          keywords: '',
          startTime: '',
          endTime: '',
          logsType: '',
          goodsType: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/coupon/queryUsageRecordList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'startTime': this.dataForm.startTime,
            'endTime': this.dataForm.endTime,
            'logsType': this.dataForm.logsType,
            'goodsType': this.dataForm.goodsType
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      }
    }
  }
</script>
